package gazzera.swing.download;

/* 
 * ColorRenderer.java (compiles with releases 1.2, 1.3, and 1.4) is used by 
 * TableDialogEditDemo.java.
 */

import gazzera.swing.model.*;
import gazzera.swing.utility.*;

import java.awt.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;


public class DownloadIconRenderer extends JLabel
                           implements TableCellRenderer {
    Border unselectedBorder = null;
    Border selectedBorder = null;
    boolean isBordered = true;
    
    public DownloadIconRenderer(boolean isBordered) {
        super();
        setHorizontalAlignment(SwingConstants.CENTER);
    	this.isBordered = isBordered;
        setOpaque(true); //MUST do this for background to show up.
        
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object o,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
    
    	if(isSelected)
    	{
    		setBackground(table.getSelectionBackground());
    	}
    	else
    	{
    		setBackground(table.getBackground());
    	}
    	String filename = ((Download)o).name;
    	String extension =  (filename.lastIndexOf(".")==-1)?"":filename.substring(filename.lastIndexOf(".")+1,filename.length());
    	
    	setIcon(Utils.getSystemIcon(extension));
    	

    	
        return this;
    }
}
